<template>
  <div class="top">
    <div class="content">
      <div class="left" @click="goHome">
        <p>预约挂号统一平台</p>
      </div>
      <div class="right">
        <div class="help">帮助中心</div>
        <div class="login" @click="login" v-if="!userStore.userInfo.name">
          登录/注册
        </div>
        <el-dropdown v-else>
          <span class="el-dropdown-link">
            {{ userStore.userInfo.name }}
            <el-icon class="el-icon--right">
              <arrow-down />
            </el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="goUser('/user/certification')">
                实名认证
              </el-dropdown-item>
              <el-dropdown-item @click="goUser('/user/order')"
                >挂号订单</el-dropdown-item
              >
              <el-dropdown-item @click="goUser('/user/patient')"
                >就诊人员管理</el-dropdown-item
              >
              <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ArrowDown } from "@element-plus/icons-vue";
// 获取user仓库的数据控制login组件的对话框显示隐藏
import useUserStore from "@/store/modules/user";
let userStore = useUserStore();
// 引入路由
import { useRouter } from "vue-router";
let $router = useRouter();
// import router from "@/router";
const goHome = () => {
  $router.push({ path: "/home" });
  // router.push({ path: "/home" });
};
// 点击登录注册按钮的时候弹出对话框
const login = () => {
  userStore.visiable = true;
};
// 会员中心
const goUser = (path: string) => {
  $router.push({
    path,
  });
};
// 退出登录
const logout = () => {
  // 通知pinia仓库清楚用户信息
  userStore.logout();
  $router.push({
    path: "/home",
  });
};
</script>

<style scoped lang="scss">
::v-deep(.el-dropdown-link) {
  color: #999 !important;
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}

.top {
  position: fixed;
  z-index: 999;
  width: 100%;
  height: 70px;
  background-color: #fff;
  display: flex;
  justify-content: center;

  .content {
    width: 1200px;
    height: 70px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;

    .left {
      display: flex;
      flex-direction: row;
      align-items: center;

      img {
        width: 50px;
        height: 50px;
        margin-right: 10px;
      }

      p {
        font-size: 22px;
        color: #55a6fe;
      }
    }

    .right {
      display: flex;
      flex-direction: row;
      align-items: center;

      div {
        font-size: 14px;
        color: #999;
        margin-left: 10px;
      }
    }
  }
}
</style>
